package com.ybdz.scanner.utils;

import android.os.Environment;

import java.io.File;

/**
 * Created by gs on 2018/3/29.
 */

public class Commen {
    public final static String SAVE_APP_NAME = "scanner.apk";

    public final static String SAVE_APP_LOCATION = "/download";


    public final static String APP_FILE_NAME = Environment.getExternalStorageDirectory().getPath()+SAVE_APP_LOCATION+ File.separator + SAVE_APP_NAME;
    public static final String DOWNLOAD_APK_ID_PREFS = "download_apk_id_prefs";

    public static void delFolder() {
        String path = Environment.getExternalStorageDirectory().getPath()+SAVE_APP_LOCATION+ File.separator;

        try {
            delAllFile(path); // 删除完里面所有内容
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 删除指定文件夹下所有文件
    // param path 文件夹完整绝对路径
    public static void delAllFile(String path) {
        File file = new File(path);
        if (!file.exists()) {
            return;
        }
        if (!file.isDirectory()) {
            return;
        }
        String[] tempList = file.list();
        File temp = null;
        for (int i = 0; i < tempList.length; i++) {
            if (path.endsWith(File.separator)) {
                temp = new File(path + tempList[i]);
            } else {
                temp = new File(path + File.separator + tempList[i]);
            }
            if (temp.isFile()) {
                temp.delete();
            }
            if (temp.isDirectory()) {
                delAllFile(path + "/" + tempList[i]);// 先删除文件夹里面的文件
            }
        }
    }
}
